import qiniu

access_key = '2psMNTrul_OS9a-qnNhrktE4jygUIGsDFg9D8qfe'
secret_key = 'RGluQW8XBgd9LPblObn6Yj_vGoECs6ZI09Hv79e9'
bucket_name = 'myhome'


def upload_file(data):
    """
    上传、存储图⽚片到七⽜牛云
    :param data: ⽂文件⼆二进制数据
    :return: FtEAyyPRhUT8SU3f5DNPeejBjMV5
    """
    q = qiniu.Auth(access_key, secret_key)
    token = q.upload_token(bucket_name)
    ret, info = qiniu.put_data(token, None, data)

    if info.status_code != 200:
        # 如果上传失败就抛出异常
        raise Exception('七⽜云上传图⽚失败')
    # 如果上传成功就返回key
    return ret.get('key')
